import router from './index'
import store from '../store'

router.beforeEach((to,from,next)=>{
    // let token = store.state.getToken?.token;
    // console.log(  to.matched.length>0 && !to.matched.some(record => record.meta.requiresAuth));
    if(!(store.state.getToken?.token)){
        if(to.matched.length>0 && !to.matched.some(record => record.meta.requiresAuth)){
            next()
        }else{
            next({path:'/login'})
        }
    }else{
        if(!store.state.loginModule.permissionlist){
            store.dispatch('loginModule/FETCH_PERMISSION').then(res=>{
                next({
                    path:to.path
                })
            })
           router.onReady(()=>{
               console.log('1')
           })
            // next()
        }else{
            if(to.path !== '/login'){
                next()
            }else{
                next(from.fullPath)
            }
        }
    }
   
})



